package cl.parser.internal;

import java.util.ArrayList;
import java.util.List;

import cl.parser.IParseNode;
import cl.parser.external.IdentifierNode;
import cl.parser.external.TypeNode;

public class FunctionDeclarationNode extends InternalNode {

    @Override
    public String prettyPrint(String indent) {
        String res = children.get(0).prettyPrint(indent) + " ";
        res += children.get(1).prettyPrint(indent) + children.get(2).prettyPrint(indent) + " ";
        res += children.get(3).prettyPrint(indent);
        
        return res;
    }
    
    @Override
    protected List<IParseNode> getAllowed(IParseNode last, List<IParseNode> soFar) {
        List<IParseNode> allowed = new ArrayList<IParseNode>();
        
        if(last == null) {
            allowed.add(new TypeNode());
        } else if(last instanceof TypeNode) {
            allowed.add(new IdentifierNode());
        } else if(last instanceof IdentifierNode) {
            allowed.add(new ArgumentDeclarationNode());
        } else if(last instanceof ArgumentDeclarationNode) {
            allowed.add(new CodeBlockNode());
        }
        
        return allowed;
    }

    @Override
    protected boolean isValid(IParseNode last, List<IParseNode> soFar) {
        return last instanceof CodeBlockNode;
    }

}
